package Leetcode.array;

public class Rotate90 {
    public void rotate(int[][] matrix) {
        int n=matrix[0].length;
         for (int i=0;i<n/2;i++) {
             for (int j = 0; j < n; j++) {
                 int t=matrix[i][j];
                 matrix[i][j]=matrix[n-i-1][j];
                 matrix[n-i-1][j]=t;
             }
         }

         for (int i=1;i<n;i++)
             for(int j=0;j<i;j++){
                 int m=matrix[i][j];
                 matrix[i][j]=matrix[j][i];
                 matrix[j][i]=m;
             }
    }


    public static void main(String[] args) {
          Rotate90 rotate=new Rotate90();
          int[][] a={{5,1,9,11},
                     {2,4,8,10},
                     {13,3,6,7},
                     {15,14,12,16}};
          rotate.rotate(a);

          for(int i=0;i<a[0].length;i++) {
              for (int j = 0; j < a[0].length; j++) {
                  System.out.print(a[i][j]+"  ");
              }
              System.out.println();
          }
    }
}
